<%@page import="java.text.SimpleDateFormat"%>
<%@page import="cn.school.tool.StringKit"%>

<%@taglib  uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib  uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>


<input type="text" name="name" id="name" placeholder="请输入姓名"  value="${name }">
<input type="text" name="qq" id="qq" placeholder="请输入qq" value="${qq }">
<input type="text" name="start" id="start" placeholder="请输入入学日期"  value="${sta }">
<input type="text" name="end" id="end" placeholder="请输入入学日期"  value="${en }">
<input type="submit" id="subm" value="chaxun">

 
<table border="1px" id="st">
<tr>
<td>学号</td>
<td>姓名</td>
<td>性别</td>
<td>telephone</td>
<td>qq</td>
<td>wechat</td>
<td>gradeid</td>
<td>enterdate</td>
<td>fromcity</td>
<td>birthday</td>
<td>address</td>
<td>pass</td>
<td>photo</td>
<td colspan="2">操作</td>
</tr>

</table>
<p>
<a href="#" id="add">增加学生</a>
</p>
 <p id="fenye">


<p id="shang">
<a href="#" id="first">首页</a>

<a href="#" id="prve">上一页</a>

<a href="#" id="next">下一页</a>

<a href="#" id="last">末页</a>
go<input id="tiaozhuan" type="number" name="tiaozhuan">页 
</p> 
<script src="../jquery-3.4.1.js"></script>
<script type="text/javascript">
<%-- $(function () {
	$("#tiaozhuan").blur(function () {
	var pagNo= $(this).val();
	$(this).next().text("<%response.sendRedirect(\"studentshow.jsp?pagNo="+pagNo +"\"); %>")
	 location.replace("./searchstudent?pagNo="+pagNo+"&&name="+$("#name").val()+"&&qq="+$("#qq").val()+"&&start="+$("#start").val()+"&&end="+$("#end").val());
	});
/* 	var json=null;
	$("input[type=submit]").click(function () {
		
		 json=[{"name":$("#name").val(),"qq":$("#qq").val(),"sta":$("#start").val(),"en":$("#end").val()}];
		 console.log(json);
		 $.get("../JsonSearchStudent",json,function(data){
				var s=$("#st");
		 		$.each(data,function(i,d){
					if(i==3){
						console.log(d.list2+"chaxun");
						$.each(d.list2,function(i,o){
							s.append("<tr><td>"+o.stuno+"</td><td>"+o.sname+"</td><td>"+o.sex+"</td><td>"+o.telephone+"</td><td>"+o.qq+"</td><td>"+o.wechat+"</td><td>"+o.gradeid+"</td><td>"+o.enterdate+"</td><td>"+o.fromcity+"</td><td>"+o.birthday+"</td><td>"+o.address+"</td><td>"+o.pass+"</td><td>"+o.photo+"</td></tr>")
						});
			
						}

				}); 

			
			});	 
		 
	}) */
	var pagNo=0;
	var pages=0;
	var a=0;
	
	$.get("../JsonSearchStudent",function(data){
		var s=$("#st");
		console.log(data);
	/* 	var json=[{"name":$("#name").val(),"qq":$("#qq").val(),"sta":$("#start").val(),"en":$("#end").val()}]; */
	/* 获取数据库值 */
 		$.each(data,function(i,d){
 			if(i==0){
 				a=d.a;
 				
 			}
 			if(i==1){
 				pagNo=d.pagNo;
 				
 			}
 			if(i==2){
 				
 				pages=d.pages
 			}
			if(i==3){
				console.log(d.list2);
				$.each(d.list2,function(i,o){
					s.append("<tr><td>"+o.stuno+"</td><td>"+o.sname+"</td><td>"+o.sex+"</td><td>"+o.telephone+"</td><td>"+o.qq+"</td><td>"+o.wechat+"</td><td>"+o.gradeid+"</td><td>"+o.enterdate+"</td><td>"+o.fromcity+"</td><td>"+o.birthday+"</td><td>"+o.address+"</td><td>"+o.pass+"</td><td>"+o.photo+"</td></tr>")
				});
	
				}
				console.log(d);
				
		}); 
	/* 查询输入值 */

 		$("#fenye").append("<span>共"+a+"条</span>");
		$("#fenye").append("<span>第"+pagNo+" /"+pages+" 页</span>");
		
	});	
	if(pagNo>=1){
	$("#shang").click(function(){
		pagNo--;
	});
     }
}); --%>
$(function () {
	var pagNo=1;
	var pages=1;
	var a=0;
	function daQuery() {
		$.get("../JsonSearchStudent",{"pagNo":pagNo,"name":$("#name").val(),"qq":$("#qq").val(),"start":$("#start").val(),"end":$("#end").val()},function(p){
			var s=$("#st");
			pagNo=p.pageNo;
			pages=p.totalPage;
			a=p.totalLines;
		/* 	var json=[{"name":$("#name").val(),"qq":$("#qq").val(),"sta":$("#start").val(),"en":$("#end").val()}]; */
		/* 获取数据库值 */
	 		$.each(p.datas,function(i,o){	 			
	 	console.log(o.list2);
		s.append(
	"<tr class='stu'><td>"+o.stuno+"</td><td>"+o.sname+"</td><td>"+o.sex+"</td><td>"+o.telephone+"</td><td>"+o.qq+"</td><td>"+o.wechat+"</td><td>"+o.gradeid+"</td><td>"+o.enterdate+"</td><td>"+o.fromcity+"</td><td>"+o.birthday+"</td><td>"+o.address+"</td><td>"+o.pass+"</td><td>"+o.photo+"</td><td><a href='#' class='dele' stuno='"+o.stuno+"'>删除</a></td><td><a href='#' class='xiugai' stuno='"+o.stuno+"'>修改</a></td></tr>")
				
			}); 
		/* 查询输入值 */
           $("#fenye").empty();
	 		$("#fenye").append("<span class='mess'>共"+a+"条</span>");
	 		$("#fenye").append("<span  class='mess'>第"+pagNo+" /"+pages+" 页</span>");
		});	
		
	}

	daQuery();
	
	$("input[type=submit]").click(function (){

		$(".stu").replaceWith(daQuery());		
		return false;
	});
	$("#first").click(function (){	
		pagNo=1;
		$(".stu").replaceWith(daQuery());		
		return false;
	});
	$("#prve").click(function (){	
		if(pagNo<=1){
			
			$(".stu").replaceWith(daQuery());		
			return false;
		}
		pagNo--;
		$(".stu").replaceWith(daQuery());		
		return false;

	});
	$("#next").click(function (){	
		if(pagNo>=pages){		
			$(".stu").replaceWith(daQuery());		
			return false;
		}
		pagNo++;
		$(".stu").replaceWith(daQuery());		
		return false;
	});
	$("#last").click(function (){	
		pagNo=pages;
		$(".stu").replaceWith(daQuery());		
		return false;
	});
	$("#tiaozhuan").blur(function () {
		pagNo=$(this).val();
		if(pagNo>pages||pagNo<1){
			return false;
		}
		$(".stu").replaceWith(daQuery());		
		
	});
	//删除学生
	$("#st").on("click",".dele",function(){
	var	stuno=$(this).attr("stuno");
	//alert(stuno);
	console.log(stuno);
	 $.get("../StudentDelAjax",{stuno:stuno},function(data){
		 alert(data.jieguo);
		 console.log(data);
		 $(".stu").replaceWith(daQuery());
		 return false;
	 });
	});
	
	//修改学生
	$("#st").on("click",".xiugai",function(){
		var	stuno=$(this).attr("stuno");
		alert(stuno);
		//console.log(stuno);
		window.location="StudentUpdata.html?"+stuno;
		return false;
/* 		 $.get("StudentUpdata.html",{stuno:stuno},function(data){
			// alert(data.jieguo);
			// console.log(data);
			
			 return false;
		 }); */
		});
	
	//增加学生
	$("#add").click(function(){
		
		window.location="StudentAdd.html";
	});

});
</script>
</body>
</html>